// user.js
import request from "../Util/axios/request.js";
//获取所有列表
export function findAllType() {
  return request.get("/life/type/findAll", null);
}
// 接收分页参数 pageNum、pageSize 和 typeId
export function findBlogByType(pageNum, pageSize, typeId) {
  // 构造包含分页和类型 ID 的参数对象
  const params = { pageNum, pageSize, typeId };
  // 调用 get 接口，传递参数
  return request.get("/life/blog/findBlogByTypeId", params, {});
}
//收藏
export function Collect(conllection) {
  return request.post("/life/conllection/add", conllection);
}
//获取用户的的收藏状态（用来改变星星的样式）
export function getIsCollected(userId, itemId) {
  const params = { userId, itemId };
  return request.get("/life/conllection/check", params, {});
}
//获取评论树结构
export function getCommentTree(itemId) {
  const params = { itemId };
  return request.get("/life/Comment/getCommentTree", params, {});
}
// 添加一级评论
export function addFirstComment(comment) {
  return request.post("/life/Comment/add", comment);
}
//回复某人的评论
export function addCommentReply(comment) {
  return request.post("/life/Comment/add", comment);
}
//删除评论
export function deleteComment(id) {
  const params = {id};
  return request.delete("/life/Comment/delete", params, {});
}
//搜索栏搜索blog
export function findBlogBySearch(BlogSearchDTO) {
  return request.post("/life/blog/search", BlogSearchDTO);
}
//根据userId查询用户的1所有信息
export function findUserInfoByUserId(userId) {
  const params = { userId };
  return request.get("/life/user/findUserInfoByUserId", params, {});
}
//获取用户的发布笔记数量
export function getPublishCount(userId) {
  const params = { userId };
  return request.get("/life/blog/publishCount", params, {});
}
//获取用户的收藏数量
export function getConllectionCount(userId) {
  const params = { userId };
  return request.get("/life/conllection/count", params, {});
}
//获取用户的评论数量
export function getCommentCount(userId) {
  const params = { userId };
  return request.get("/life/Comment/count", params, {});
}
//查询用户发布的所有blog
export function findUserBlog(pageNum, pageSize, userId) {
  const params = { pageNum, pageSize, userId };
  return request.get("/life/blog/findUserBlog", params, {});
}
//查询用户收藏的所有blog
export function findUserCollectBlog(pageNum, pageSize, userId) {
  const params = { pageNum, pageSize, userId };
  return request.get("/life/blog/findUserCollectBlog", params, {});
}
//修改个人信息
export function updateByUserId(User) {
  return request.put("/life/user/updateUserInfo", User);
}
//获取ip地址
export function findlocation(ip) {
  const params = { ip };
  return request.get("/life/location/getLocation", params, {});
}
//获取关注列表中的所有对象信息
export function getFollowedList(followerId) {
  const params = { followerId };
  return request.get("/life/follow/getFollowedList", params, {});
}
//获取历史记录
export function getChat(publisherId,consumerId) {
  const params = { publisherId,consumerId };
  return request.get("/life/Chat/getChat", params, {});
}
//上传文件
export function uploadFileToServer(file) {
  // 创建 FormData 对象，将文件添加到表单中
  const formData = new FormData();
  formData.append('file', file); // 'file' 需与后端 @RequestParam("file") 保持一致

  return request.post("/life/blog/upload", formData, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}
// 发布图片类型博客
export function addImg(Blog) {
  return request.post("/life/blog/addImg", Blog);
}

// 发布视频类型博客
export function addVideo(Blog) {
  return request.post("/life/blog/addVideo", Blog);
}
//上传文件 使用minio上传视频
export function uploadFileToMinio(file) {
  // 创建 FormData 对象，将文件添加到表单中
  const formData = new FormData();
  formData.append('file', file); // 'file' 需与后端 @RequestParam("file") 保持一致
  return request.post("/life/minio/upload", formData, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}